<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
  <title>用户信息查询</title>
  <style type="text/css">
    table {
      border-collapse: collapse;
      border: 1px black solid;
    }
    td {
      border: 1px solid;
      text-align: center;
    }
  </style>
</head>
<body>
<div align="center">
  <fieldset>
    <legend>添加用户</legend>
    <form method="post" action="user/add">
      <input type="text" name="name" placeholder="名字">
      <select name="sex" title="性别">
        <option value="1">男</option>
        <option value="0">女</option>
      </select>
      <input type="text" name="birthday" placeholder="生日（yyyy-MM-dd）">
      <input type="text" name="telephone" maxlength="14" placeholder="电话">
      <input type="text" name="email" maxlength="30" placeholder="电子邮件">
      <textarea name="address" placeholder="地址"></textarea>
      <button onclick="this.parentNode.submit()">添加</button>
    </form>
  </fieldset>
  <fieldset>
    <legend>查询用户</legend>
    <form method="post" action="users">
      <input type="text" name="name" placeholder="名字">
      <select name="sex" title="性别">
        <option value="">未指定</option>
        <option value="1">男</option>
        <option value="0">女</option>
      </select>
      <input type="text" name="telephone" maxlength="14" placeholder="电话">
      <input type="text" name="email" maxlength="30" placeholder="电子邮件">
      <textarea name="address" placeholder="地址"></textarea>
      <input type="submit" value="查询">
    </form>
  </fieldset>
  <c:out value="${sessionScope['time']}" />
  <c:if test="${requestScope.users.size()>0}">
    <table style="border: 1px black solid; width: 70%">
      <tr>
        <th width="50">ID</th>
        <th>名字</th>
        <th>性别</th>
        <th>生日</th>
        <th>电话</th>
        <th>电邮</th>
        <th>地址</th>
        <th>操作</th>
      </tr>
      <c:forEach items="${requestScope.users}" var="user">
        <tr>
          <td>${user.id}</td>
          <td>${user.name}</td>
          <td>
            <c:choose>
              <c:when test="${user.sex=='1'}">
                <c:out value="男" />
              </c:when>
              <c:otherwise>
                <c:out value="女" />
              </c:otherwise>
            </c:choose>
          </td>
          <td><fmt:formatDate value="${user.birthday}" pattern="yyyy-MM-dd" /></td>
          <td>${user.telephone}</td>
          <td>${user.email}</td>
          <td>${user.address}</td>
          <td>
            <%-- <a href="${pageContext.request.contextPath}/user?id=${user.id}">编辑</a> --%>
            <a href="user/${user.id}">编辑</a>
            <form action="user/remove" method="post">
              <input type="hidden" name="id" value="${user.id}" readonly>
              <button>删除</button>
            </form>
          </td>
        </tr>
      </c:forEach>
    </table>
  </c:if>
</div>
</body>
</html>
